package action;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import org.hibernate.Session;
import org.hibernate.Transaction;

import classes.Employe;

import sessionfactory.HibernateSessionFactory;



public class AddEmployeAction extends Action {
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception 
			{
				Session session = HibernateSessionFactory.getSessionFactory().openSession();
				Transaction tx = session.beginTransaction();
				
				Employe toadd = new Employe ();
				toadd.setCivilite(request.getParameter("civilite"));
				toadd.setNom(request.getParameter("nom"));
				toadd.setPrenom(request.getParameter("prenom"));
				toadd.setMail(request.getParameter("mail"));
				toadd.setPwd(request.getParameter("password"));
				toadd.setContratHoraire(Integer.valueOf(request.getParameter("contratHoraire")));
				toadd.setAddresse(request.getParameter("adresse"));
				toadd.setCodePostal(Integer.valueOf(request.getParameter("cp")));
				toadd.setVille(request.getParameter("ville"));
				toadd.setTelephone((Integer.valueOf(request.getParameter("telephone"))));
				toadd.setStatus(request.getParameter("status"));
				toadd.setLogin(request.getParameter("login"));
				session.save(toadd);
				tx.commit();
				return mapping.findForward("Success");	
			}	
}
